//
//  BaseViewController.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/7/21.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SVProgressHUD

class BaseViewController: UIViewController {
    
    
//    var needPayMoney = "0.0"

    
    lazy var plainTableView : BaseTableView = {
        

                let temp = BaseTableView(frame: UIScreen.main.bounds, style: .plain)
        
                temp.delegate = self
        
                temp.dataSource = self
        
                temp.showsVerticalScrollIndicator = false
        
                temp.showsHorizontalScrollIndicator = false
        
                temp.allowsSelection = true
        
                self.view.addSubview(temp)
        
        
        
        return temp
        
    }()
    
    lazy var groupTableView : BaseTableView = {
        
        let temp = BaseTableView(frame: UIScreen.main.bounds, style: .grouped)
        
        temp.delegate = self
        
        temp.dataSource = self
        
        temp.showsVerticalScrollIndicator = false
        
        temp.showsHorizontalScrollIndicator = false
        
        temp.allowsSelection = true
        
        self.view.addSubview(temp)
        
        return temp
        
    }()
    
    
    lazy var surpriseTable : SurpriseShopColumnTable = {
        
        let temp = SurpriseShopColumnTable(frame: self.view.bounds, style: .plain)
        
        temp.delegate = self
        
        temp.dataSource = self
        
        temp.showsVerticalScrollIndicator = false
        
        temp.showsHorizontalScrollIndicator = false
        
        temp.allowsSelection = true
        
        self.view.addSubview(temp)
        
        return temp
        
    }()
    
    
    lazy var logoImageView : UIImageView = {
        
        let temp = UIImageView(image: UIImage(named: "gray"))
        
        temp.frame = CGRect(x: 0, y: 0, width: 100, height: 60)
        
        
        return temp
        
    }()
    
    
    lazy var logoLabel : UILabel = {
        
        let temp = UILabel(frame: CGRect(x: -15, y: 72, width: 130, height: 28))
        
        temp.text = "你还没有相关订单..."
        
        temp.textAlignment = .center
        
        temp.font = UIFont.systemFont(ofSize: 14)
        
        temp.textColor = UIColor.dakGray()
        
        return temp
        
    }()
    
    
    lazy var logoView : UIView = {
    
        let temp = UIView(frame: CGRect(x: (KScreenW - 100) * 0.5, y: (KScreenH - 100) * 0.5, width: 100, height: 100))
    
        temp.addSubview(self.logoImageView)
    
        temp.addSubview(self.logoLabel)

        self.view.addSubview(temp)
        
          return temp
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.randomColor()
        

    }
    
    func showLogoView(text : String){
        
        logoView.isHidden = false
        
        logoLabel.text = text
    }
    
    func dissmissLogoView() {
        logoView.isHidden = true

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
 
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        

        if vipPushTag == false {
            
            navigationController?.setNavigationBarHidden(false, animated: true)

        }
        
    }
    
    
    
    func performIsLoginJump(aSelector : Selector?,target: UIViewController?){
        
        if target == nil {
            
            login()
            
            return
        }

        
        if UserViewModel.shared.userIsLogin() == true {
            
            target!.perform(aSelector)
            
        } else {
            
            login()
            
        }
        
    }
    
    
    func clearData(){
        UserViewModel.shared.user = nil
        
        let fileManager = FileManager.default
        
        do {
            
            try fileManager.removeItem(atPath:"accout.plist".cacheDir())
            
        } catch  {
            
            QL1("删除失败")
            
        }
        
        
        
        let temp = UserDefaults.standard.value(forKey: "IsNewCityUser")
        
        if let hehe = temp as? String {
            
            if hehe == "TRUE" {
                
                UserDefaults.standard.set("FALSE", forKey: "IsNewCityUser")
                
                UIApplication.shared.keyWindow?.rootViewController = TabBarController()
                
            }
        }

        
        
        
        
        
        SVProgressHUD.showSuccess(withStatus: "注销成功!")
        
        
    }

    
    
    
    func login(){
        

        
        
        let log = LoginViewController()
        
        
        present(BaseNavController(rootViewController: log), animated: true, completion: nil)
        
    }
    
    
    deinit{
        
//        let temp = self.classString() + "控制器销毁了!"
    
        QL1("控制器销毁了!")
        
    }
    
    
    
    


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}


extension BaseViewController : UITableViewDelegate,UITableViewDataSource{
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 0
    }
    
    
    func numberOfSections(in tableView: UITableView) -> Int {
        
        return 0
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        return UITableViewCell()
        
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        tableView.deselectRow(at: indexPath, animated: true)
    }
    



}




